var resultDom = document.getElementById("result");
var isOperated = false; // 是否输入了运算符

var isStarted = false; // 是否开始了
var isDecimalAdded = false; // 是否输入了小数点


//点击计算器执行函数

//输入数字
function appendNum(num) {
    var str = resultDom.value;
    str = (str == "0" ? "" : str);

    isOperated = false;
    if (num == 'two 0') {
        str += 0;
        str += 0;

        resultDom.value = str;
        isStarted = true;

    } else {
        str += num;

        resultDom.value = str;
        isStarted = true;
    }

}

//输入运算符
function append(p) {
    if (!isOperated) {
        var num = resultDom.value;
        num = (num == "0" ? "" : num);

        resultDom.value = num + p;

        isDecimalAdded = false;
        isOperated = true; //防止同时输入两个运算符

    }
}

// 输入=； 计算结果
function equal() {
    var result = resultDom.value;
    result = result.replace(new RegExp('×', 'g'), '*').replace(new RegExp('÷', 'g'), '/');
    var r = eval(result); //eval(string),要计算的字符串，其中含有要计算的 JavaScript 表达式或要执行的语句。

    resultDom.value = r;
    // isDecimalAdded=false;
    isOperated = false;


}

//输入AC 清空
function clearzero() {
    resultDom.value = 0;
    isDecimalAdded = false;
    isStarted = false;
    isStarted = false;
    isSmalle = false;
    isOperated = false;
}



// 输入+-号，变号
function calToggle() {
    if (isOperated || !isStarted) {
        return;
    }
    var str = resultDom.value;
    str += '×';
    str += '-1';

    resultDom.value = str;
    equal();

}

// 输入百分号，*0.01
function calPercentage() {
    if (isOperated || !isStarted) {
        return;
    }
    var str = resultDom.value;
    str += '×';
    str += '0.01';

    resultDom.value = str;
    equal();


}

// 输入小数点
function dot(m) {
    if (isDecimalAdded) {
        return;
    }
    if (isOperated) {
        resultDom.value += '0';
    }
    var str = resultDom.value;
    str += m;

    resultDom.value = str;
    isDecimalAdded = true;
    isOperated = true;


}